#!/bin/sh

# will be runned before ant, ant deploy so any settings should be set here

# must not fail
set -e 

# debug
#set -x 
echo "Starting $0"

if [ -f /usr/local/certificate-services/environment ] ; then
	source /usr/local/certificate-services/environment 
else
	echo "cant find /usr/local/certificate-services/environment, exiting"
	exit
fi

perl -pi -e "s/token.usesamepin=.*/token.usesamepin=TRUE/gio" ${HTMF_HOME}/src/resources/globalsettings/global.properties
perl -pi -e "s/usenonadminfunctionality=.*/usenonadminfunctionality=TRUE/gio" ${HTMF_HOME}/src/resources/globalsettings/global.tolima.properties
perl -pi -e "s/errorcontroller.promptforreportsending=.*/errorcontroller.promptforreportsending=FALSE/gio" ${HTMF_HOME}/src/resources/globalsettings/global.properties
perl -pi -e "s/setcardtypecontroller.regularvaliddefault.*/setcardtypecontroller.regularvaliddefault=1095/gio" ${HTMF_HOME}/src/resources/globalsettings/global.properties
perl -pi -e "s/createcarddonecontroller.letusersetpin=false/createcarddonecontroller.letusersetpin=true/gio" ${HTMF_HOME}/src/resources/globalsettings/global.properties
perl -pi -e "s/pinlockedcontroller.pin.minlength=.*/pinlockedcontroller.pin.minlength=6/gio" ${HTMF_HOME}/src/resources/globalsettings/global.properties
perl -pi -e "s/pinlockedcontroller.pin.maxlength=.*/pinlockedcontroller.pin.maxlength=8/gio" ${HTMF_HOME}/src/resources/globalsettings/global.properties
perl -pi -e "s/setcardtypecontroller.enablenameoverride.*/setcardtypecontroller.enablenameoverride = TRUE/gio" ${HTMF_HOME}/src/resources/globalsettings/global.properties


# use a User Data source
#perl -pi -e "s/\#ejbcaws.userdatasourcenames=.*/ejbcaws.userdatasourcenames=TESTUDS/gio" ${HTMF_HOME}/src/resources/globalsettings/global.properties
# to enforce the data from the UDS add the line below
# also comment out the above line that sets this option to TRUE
#perl -pi -e "s/setcardtypecontroller.enablenameoverride.*/setcardtypecontroller.enablenameoverride = FALSE/gio" ${HTMF_HOME}/src/resources/globalsettings/global.properties
# some like the old version of the swedish pnr
#perl -pi -e "s/creatingcardcontroller.normalizedsn.type=newswedishpersonalnumber/creatingcardcontroller.normalizedsn.type=oldswedishpersonalnumber/gio" ${HTMF_HOME}/src/resources/globalsettings/global.properties
echo "end of $0"
